package com.xiaodu.mybatis.controller;

import com.xiaodu.mybatis.entity.UserEntity;
import com.xiaodu.mybatis.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author: dutianjie
 * @date: 2021/4/16
 * @version: v1.0.0
 * @description: 描述
 **/
@RestController
@RequestMapping("user")
public class UserController {

    @Autowired
    private UserService userService;

    @GetMapping
    public UserEntity getUserOne(@RequestParam String id) throws Exception {
        return userService.oneUser(id);

    }

    @GetMapping("page")
    public List<UserEntity> pageUser(@RequestParam(defaultValue = "1") Integer pageNo,
                                     @RequestParam(defaultValue = "5") Integer pageSize) throws  Exception {
        return userService.pageUser(pageNo, pageSize);
    }

    @GetMapping("batch")
    public List<UserEntity> batchUser(@RequestParam List<String> ids) throws Exception {
        return userService.listUser(ids);
    }

    @PostMapping
    public UserEntity addUser(@RequestBody UserEntity userEntity) throws Exception {
        return userService.addUser(userEntity);
    }

    @DeleteMapping
    public void removeUser(@RequestParam String id) throws Exception {
         userService.delUser(id);
    }

    @PutMapping
    public void updateUser(@RequestBody UserEntity userEntity) throws Exception {
        userService.updateUser(userEntity);

    }



}
